home *** CD-ROM | disk | FTP | other *** search
- /*
- ** GETALL.C
- **
- ** This program downloads all files with a specified file extension from
- ** a FTP server. To use this program, first edit the #define's below
- ** (SRVR_NAME, USER_NAME, etc.). Note that file extensions are case sensitive.
- ** Be sure to set IS_BINARY to TRUE if binary files are to be downloaded.
- **
- */
-
- #include <windows.h>
- #include <winsock.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include "fce.h"
-
- #define SRVR_NAME "10.0.0.1"
- #define USER_NAME "mike"
- #define PASSWORD "mike"
- #define DIRECTORY "."
- #define FILE_EXT ".TXT"
- #define IS_BINARY FALSE
-
- #define LIST_SIZE 5000
- #define LINE_SIZE 100
-
- char LineBuffer[LINE_SIZE];
- char ListBuffer[LIST_SIZE];
-
- char Temp[51];
-
- /* globals */
-
- void ShowError(int Code)
- {Temp[0] = '\0';
- fceErrorText(0,Code,(LPSTR)Temp,50);
- printf("ERROR %d: %s\n", Code, Temp);
- }
-
- void ErrorExit(int Code)
- {ShowError(Code);
- fceRelease();
- exit(1);
- }
-
- LPSTR FindExtension(LPSTR Filename)
- {int i, Len;
- char c;
- LPSTR Ptr;
- Len = strlen(Filename);
- if(Len<=1) return NULL;
- Ptr = Filename + Len - 1;
- for(i=Len-1;i>0;i--)
- {c = *Ptr;
- if(c=='.') return Ptr;
- Ptr--;
- }
- return NULL;
- }
-
- void main(int argc, char *argv[])
- {int n, Code;
- int FileCount = 0;
- int Version;
- int Build;
- LPSTR Ptr;
- /* check arguments */
- if(argc!=1)
- {printf("Usage: GETALL\n");
- exit(1);
- }
- printf("GETALL 03/01/1999\n");
- printf("Server : %s\n", SRVR_NAME);
- printf(" User : %s\n", USER_NAME);
- printf(" Pass : %s\n", PASSWORD);
- printf(" Dir : %s\n", DIRECTORY);
- printf(" Files : *%s\n", FILE_EXT);
- /* attach FCE */
- Code = fceAttach(1);
- if(Code<0) ErrorExit(Code);
- Version = fceGetInteger(0,FCE_GET_VERSION);
- Build = fceGetInteger(0,FCE_GET_BUILD);
- printf("FCE32 Version: %1d.%1d.%1d Build %d\n",
- 0x0f&(Version>>8),0x0f&(Version>>4),0x0f&Version,Build);
- fceGetString(0,FCE_GET_REGISTRATION,(LPSTR)Temp,50);
- printf(" Registration: %s\n", Temp);
- /* define LOG file */
- ///Code = fceSetString(0,FCE_SET_LOG_FILE,(LPSTR)"getall.log");
- /* connect to server */
- printf("Connecting to %s ... ",SRVR_NAME);
- Code = fceConnect(0,(LPSTR)SRVR_NAME,(LPSTR)USER_NAME,(LPSTR)PASSWORD);
- if(Code<0) ErrorExit(Code);
- printf("OK\n");
- /* change to proper directory ["." is current directory] */
- if(strcmp(DIRECTORY,".")!=0)
- {printf("Changing to server directory '%s'\n", DIRECTORY);
- Code = fceSetServerDir(0, (LPSTR)DIRECTORY);
- if(Code<0) ErrorExit(Code);
- }
- /* set transfer mode */
- #if IS_BINARY
- {printf("Setting BINARY transfer mode.\n");
- fceSetMode(0,'B');
- }
- #else
- {printf("Setting ASCII transfer mode.\n");
- fceSetMode(0,'A');
- }
- #endif
- /* get file list */
- Code = fceGetList(0, FCE_NAME_LIST, (LPSTR)ListBuffer, LIST_SIZE);
- if(Code<0) ErrorExit(Code);
- /* get each filename */
- for(n=1;;n++)
- {/* extract next filename from downloaded list */
- Code = fceExtract((LPSTR)ListBuffer, n, 0, (LPSTR)LineBuffer, LINE_SIZE);
- if(Code<=1) break;
- ///printf("Filename = [%s]\n", LineBuffer);
- /* find filename extention */
- Ptr = FindExtension(LineBuffer);
- if(Ptr)
- {/* does extension match ? */
- if(strcmp(Ptr,(LPSTR)FILE_EXT)==0)
- {/* download this file */
- printf("Downloading file '%s' ... ",LineBuffer);
- Code = fceGetFile(0,(LPSTR)LineBuffer);
- printf("OK\n");
- if(Code<0) ErrorExit(Code);
- FileCount++;
- }
- else
- {/* skip this file */
- printf("Skipping file '%s'\n",LineBuffer);
- }
- }
- }
- printf("%d files downloaded.\n", FileCount);
- /* QUIT */
- fceClose(0);
- fceRelease();
- }
-
-